


function s() {

    var a = document.querySelectorAll(".main .cart-list .item-form")
    //总价
    var b = document.querySelector("#allCont")
    //先让总价等于0
    b_text = 0

    for(var i=0;i<a.length;i++){

        //找到单价的位置
        //console.log(a[i].children[0].children[1].children[0].children[0].children[0].children[0].children[0].innerHTML)
        var span = a[i].children[0].children[1].children[0].children[0].children[0].children[0].children[0].innerHTML

        //找到数量的位置
        // console.log(a[i].children[0].children[1].children[0].children[0].children[0].children[1].children[0].value)
        var num = a[i].children[0].children[1].children[0].children[0].children[0].children[1].children[0].value

        //找到小计的位置
        // console.log(a[i].children[0].children[1].children[0].children[0].children[0].children[2].children[0].innerHTML)
                                                                                                                        //单价乘与数量等于小计
        var pad = a[i].children[0].children[1].children[0].children[0].children[0].children[2].children[0].innerHTML = (span * num).toFixed(2)
        console.log(pad)

        b_text += Number(pad)
    }

    //赋值总价，总价取小数点后两位
    b.innerHTML = b_text.toFixed(2)
}


s()




//修改input数量功能
//获取td中所有的input数量
var ipt = document.querySelectorAll(".td .ipt")

for(var h =0;h < ipt.length;h++){
    ipt[h].addEventListener('change',s)
}




//删除功能
var add = document.querySelectorAll(".del")
for(var k = 0;k < add.length;k++){
    add[k].addEventListener('click',function () {
        //根据父级删除子级
        var mains = document.querySelector(".main")
        var main = document.querySelector(".main .cart-list")
        mains.removeChild(main)
        //删除后执行一遍函数
        s()
    })
}
